package manager

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import app.AppContext
import db.Order
import ext.log


class DataBaseManager private constructor(context: Context) :

    SQLiteOpenHelper(context, "vm.db", null, 2),
    Runnable
{

    companion object {

        val Instance: DataBaseManager by lazy { DataBaseManager(AppContext) }
    }

    override fun onCreate(sql: SQLiteDatabase) {
        log("数据库创建:onCreate")
    }

    override fun onUpgrade(sql: SQLiteDatabase, p1: Int, p2: Int) {
        log("数据库升级:$p1 ==> $p2")

        AsyncTask.post(this)
    }

    override fun run() {

        try {
            Order.dropTable()
            Order.createTable()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

}
